package com.example.userdemo.controller;


import com.alibaba.fastjson.JSON;
import com.example.userdemo.entity.Trace;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;

@RestController
public class KafkaController {
    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    @GetMapping ("/send")
    public void sendMsg(){
        Trace trace = new Trace();
        trace.setIp("10.195.23.74");
        trace.setXtraceid("02bf6e6e-c731-4ea5-a306-78b51039e199");
        trace.setTime(LocalDateTime.now());
        trace.setTarget("com.eastmoney.ementerprisemanagementweb.service.impl.HkPopRankServiceImpl.popRankTendency");
        String string_trace = JSON.toJSONString(trace);
        kafkaTemplate.send("test", string_trace);
    }

}
